package com.saltedfish.tool.view.calendar;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.text.TextUtils;
import android.util.Log;

import com.haibin.calendarview.Calendars;
import com.haibin.calendarview.MonthView;

import cn.droidlover.xdroidmvp.log.XLog;

/**
 * 高仿魅族日历布局
 * Created by huanghaibin on 2017/11/15.
 */

public class StartMonthView extends MonthView {

    private int mRadius;
    private Paint mSolarTermTextPaint = new Paint();

    public StartMonthView(Context context) {
        super(context);
        mSelectTextPaint.setColor(0xffffffff);
        mSolarTermTextPaint.setColor(0xff3097FF);
        mSolarTermTextPaint.setAntiAlias(true);
        mSolarTermTextPaint.setTextAlign(Paint.Align.CENTER);
    }

    @Override
    protected void onPreviewHook() {
        mSolarTermTextPaint.setTextSize(mCurMonthLunarTextPaint.getTextSize());
        mRadius = Math.min(mItemWidth, mItemHeight) / 6 * 2;
        // mSchemePaint.setStyle(Paint.Style.STROKE);
    }

    @Override
    protected void onLoopStart(int x, int y) {

    }

    @Override
    protected boolean onDrawSelected(Canvas canvas, Calendars calendar, int x, int y, boolean hasScheme) {
        int cx = x + mItemWidth / 2;
        int cy = y + mItemHeight / 2;
        canvas.drawCircle(cx, cy, mRadius, mSelectedPaint);
        return true;
    }

    @Override
    protected void onDrawScheme(Canvas canvas, Calendars calendar, int x, int y) {
        int cx = x + mItemWidth / 2;
        int cy = y + mItemHeight / 2;
        canvas.drawCircle(cx, cy, mRadius, mSchemePaint);
        float baselineY = mTextBaseLine + y;
        canvas.drawText(String.valueOf(calendar.getDay()),
                cx,
                baselineY,
                mSelectTextPaint);
    }

    @Override
    protected void onDrawText(Canvas canvas, Calendars calendar, int x, int y, boolean hasScheme, boolean isSelected) {
        float baselineY = mTextBaseLine + y;
        int cx = x + mItemWidth / 2;
      //  Log.e("---2-->onDrawText>",""+calendar.toString());
//        if(calendar.isCheck()){
//            canvas.drawText(calendar.getScheme(), cx, mTextBaseLine + y + mItemHeight/3,
//                    !TextUtils.isEmpty(calendar.getScheme()) ? mSolarTermTextPaint : mSchemeLunarTextPaint);
//        }
        boolean isInRange = isInRange(calendar);
        boolean isEnable = !onCalendarIntercept(calendar);

        // mOtherMonthTextPaint.setColor(0xff3097FF);
        if (isSelected) {
            canvas.drawText(String.valueOf(calendar.getDay()),
                    cx,
                    baselineY,
                    mSelectTextPaint);
//            canvas.drawText(calendar.getLunar(), cx, mTextBaseLine + y + mItemHeight/3,
//                    !TextUtils.isEmpty(calendar.getSolarTerm()) ? mSolarTermTextPaint : mSchemeLunarTextPaint);

        } else if (hasScheme) {
            XLog.e("------->>>"+calendar.toString());
//            canvas.drawText(String.valueOf(calendar.getDay()),
//                    cx,
//                    baselineY,
//                    mSelectTextPaint);

//            canvas.drawText(String.valueOf(calendar.getDay()),
//                    cx,
//                    baselineY,
//                    calendar.isCurrentDay() ? mCurDayTextPaint :
//                            calendar.isCurrentMonth()   && isEnable ? mSchemeTextPaint : mOtherMonthTextPaint);

//            canvas.drawText(calendar.getLunar(), cx, mTextBaseLine + y + mItemHeight/3,
//                    !TextUtils.isEmpty(calendar.getSolarTerm()) ? mSolarTermTextPaint : mSchemeLunarTextPaint);

        } else {
            canvas.drawText(String.valueOf(calendar.getDay()), cx, baselineY,
                    calendar.isCurrentDay() ? mCurDayTextPaint :
                            calendar.isCurrentMonth()  && isEnable ? mCurMonthTextPaint : mOtherMonthTextPaint);

//                        canvas.drawText(calendar.getLunar(), cx, mTextBaseLine + y + mItemHeight/3,
//                    calendar.isCurrentDay() ? mCurDayLunarTextPaint :
//                            calendar.isCurrentMonth() ? !TextUtils.isEmpty(calendar.getSolarTerm()) ? mSolarTermTextPaint :
//                                    mCurMonthLunarTextPaint : mOtherMonthLunarTextPaint);

        }
    }
}
